<?php


namespace app\admin\business;


use think\Exception;
use think\facade\Db;

class Article {
    public $articleObj = null;

    public function __construct() {
        $this->articleObj = new \app\admin\model\Article();
    }

    public function showArticle($id) {
        $res = $this->articleObj->showArticle($id);
        return $res;
    }

    public function saveArticle($data, $isNew = true) {
        if ($isNew) {
            $res = $this->articleObj->addArticle($data);
        } else {
            $res = $this->articleObj->editArticle($data);
        }
        return $res;
    }

    public function getListByCategoryId($category_id, $num, $searchData) {
        $articleList = $this->articleObj->getListByCategoryId($category_id, $num, $searchData);
        $result = $articleList->toArray();
        $result['render'] = $articleList->render();
        return $result;
    }

    public function statusModById($id) {
        $res = $this->articleObj->statusModById($id);
        return $res;
    }

    public function delById($id) {
        $res = $this->articleObj->delById($id);
        return $res;
    }

    public function getArticleById($id) {
        $article = $this->articleObj->getArticleById($id);
        return $article;
    }

    public function delByIds($ids) {
        $res = $this->articleObj->delByIds($ids);
        return $res;
    }
}